﻿package mortal.game.view.copy.guildDefenseCopy
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildDefenseCopyPassWin extends Window
    {
        private var _resultBg:GImageBitmap;
        private var _resultIcon:GImageBitmap;
        private var _enterBtn:GLoadingButton;
        private var _title:GTextFiled;
        private var _contribution:GTextFiled;
        private var _contributionAdd:GTextFiled;
        private var _contributionTotal:GTextFiled;
        private var _resource:GTextFiled;
        private var _resultTxt:GTextFiled;
        private var _resourceAdd:GTextFiled;
        private var _resourceTotal:GTextFiled;
        private static var _instance:GuildDefenseCopyPassWin;

        public function GuildDefenseCopyPassWin(param1:ILayer = null)
        {
            this.setSize(625, 303);
            this.layer = LayerManager.fullScreenLayer;
            if (_instance != null)
            {
                throw new Error(" GuildDefenceCopyPassWin 单例 ");
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GuildDefenceRewardPanelBg, 0, 0, this));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ChallengPassBgWumen, -90, -125, this));
            pushUIToDisposeVec(UIFactory.bg(185, 136, 440, 1, this, ImagesConst.SplitLine6));
            pushUIToDisposeVec(UIFactory.bg(185, 179, 440, 1, this, ImagesConst.SplitLine6));
            this._resultBg = UIFactory.gImageBitmap("", 130, -202, this);
            this._resultIcon = UIFactory.gImageBitmap("", 300, -102, this);
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GuildDefenceCopyTxt_5, 197, 150, this));
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.GuildDefenceCopyTxt_6, 197, 190, this));
            var _loc_1:* = GlobalStyle.textFormatHuang2.center();
            _loc_1.size = 14;
            pushUIToDisposeVec(UIFactory.gTextField(this.getDifNameByLevel(Cache.instance.copy.guildDefence.difficult), 185, 100, 100, 25, this, _loc_1, true));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35276), 423, 100, 100, 25, this, _loc_1));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35277), 530, 100, 100, 25, this, _loc_1));
            this._resultTxt = UIFactory.gTextField(Language.getString(35278), 290, 100, 100, 25, this, _loc_1);
            _loc_1 = GlobalStyle.textFormatBai.center();
            _loc_1.size = 17;
            _loc_1.bold = true;
            this._contribution = UIFactory.gTextField("1", 290, 188, 100, 25, this, _loc_1);
            this._contributionAdd = UIFactory.gTextField("1", 423, 188, 100, 25, this, _loc_1);
            this._contributionTotal = UIFactory.gTextField("1", 530, 188, 100, 25, this, _loc_1);
            this._resource = UIFactory.gTextField("1", 290, 148, 100, 25, this, _loc_1);
            this._resourceAdd = UIFactory.gTextField("1", 423, 148, 100, 25, this, _loc_1);
            this._resourceTotal = UIFactory.gTextField("1", 530, 148, 100, 25, this, _loc_1);
            pushUIToDisposeVec(UIFactory.gTextField("+", 350, 187, 100, 25, this, _loc_1));
            pushUIToDisposeVec(UIFactory.gTextField("+", 350, 147, 100, 25, this, _loc_1));
            pushUIToDisposeVec(UIFactory.gTextField("=", 490, 187, 100, 25, this, _loc_1));
            pushUIToDisposeVec(UIFactory.gTextField("=", 490, 147, 100, 25, this, _loc_1));
            this._enterBtn = UIFactory.gLoadingButton(ResFileConst.leaveCopy, 337, 245, 137, 39, this);
            this._enterBtn.configEventListener(MouseEvent.CLICK, this.closeBtnClickHandler);
            this._resultBg.imgUrl = ImagesConst.ChallengLight;
            this._resultIcon.imgUrl = ImagesConst.TianDiRangChallengeSuccessTip;
            return;
        }// end function

        override protected function closeBtnClickHandler(event:MouseEvent) : void
        {
            super.hide();
            if (CopyUtil.isInCopy)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyLeave, null));
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._resultBg.dispose(param1);
            this._resultBg = null;
            this._resultIcon.dispose(param1);
            this._resultIcon = null;
            this._enterBtn.dispose(param1);
            this._enterBtn = null;
            this._contribution.dispose(param1);
            this._contribution = null;
            this._contributionAdd.dispose(param1);
            this._contributionAdd = null;
            this._contributionTotal.dispose(param1);
            this._contributionTotal = null;
            this._resource.dispose(param1);
            this._resource = null;
            this._resourceAdd.dispose(param1);
            this._resourceAdd = null;
            this._resourceTotal.dispose(param1);
            this._resourceTotal = null;
            this._resultTxt.dispose(param1);
            this._resultTxt = null;
            return;
        }// end function

        private function getDifNameByLevel(param1:int) : String
        {
            var _loc_2:String = "";
            switch(param1)
            {
                case 4:
                {
                    _loc_2 = Language.getString(35271);
                    break;
                }
                case 8:
                {
                    _loc_2 = Language.getString(35272);
                    break;
                }
                case 12:
                {
                    _loc_2 = Language.getString(35273);
                    break;
                }
                case 16:
                {
                    _loc_2 = Language.getString(35274);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_2;
        }// end function

        public function updateInfo(param1:SGuildDefenseMemberReward) : void
        {
            var _loc_2:* = GuildDefenseConfig.instance.getCopyDefenseByLevel(Cache.instance.copy.guildDefence.guildDefenseOpenInfo.level);
            if (param1.blood > 0)
            {
                this._contribution.text = _loc_2.contribution.toString();
                this._contributionAdd.text = param1.contribution - _loc_2.contribution + "";
                this._contributionTotal.text = param1.contribution + "";
                this._resultTxt.text = Language.getString(35279);
                this._resource.text = _loc_2.resource.toString();
                this._resourceAdd.text = param1.resource - _loc_2.resource + "";
                this._resourceTotal.text = param1.resource + "";
                this._resultBg.imgUrl = ImagesConst.ChallengLight;
                this._resultIcon.imgUrl = ImagesConst.TianDiRangChallengeSuccessTip;
            }
            else
            {
                this._contribution.text = (_loc_2.contribution * 0.5).toString();
                this._contributionAdd.text = "0";
                this._contributionTotal.text = param1.contribution + "";
                this._resultTxt.text = Language.getString(35280);
                this._resource.text = (_loc_2.resource * 0.5).toString();
                this._resourceAdd.text = "0";
                this._resourceTotal.text = param1.resource + "";
                this._resultBg.imgUrl = ImagesConst.ChallengDark;
                this._resultIcon.imgUrl = ImagesConst.TianDiRangChallengeFailedTip;
            }
            return;
        }// end function

        public static function get instance() : GuildDefenseCopyPassWin
        {
            if (_instance == null)
            {
                _instance = new GuildDefenseCopyPassWin;
            }
            return _instance;
        }// end function

    }
}
